package com.chengzhi.disruptor.multi;

import com.lmax.disruptor.RingBuffer;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public class OrderProducer {

    private RingBuffer<Order> ringBuffer;

    public OrderProducer(RingBuffer<Order> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void send(int id) {
        long sequence = ringBuffer.next();
        try {
            Order order = ringBuffer.get(sequence);
            order.setId(id);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ringBuffer.publish(sequence);
        }
    }
}
